package com.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bean.Role;
import com.bean.RolePermission;
import com.bean.User;
import com.service.RoleService;
import com.service.UserService;

/**
 * @author  author : 张鹏
 * @date createTime：2018年3月19日 上午9:54:33 
 * @Description: 该类的功能描述
 */
@Controller
@RequestMapping("role")
public class RoleController {
	@Autowired
	private RoleService roleService;
	
	
	private Role role;
	
	@RequestMapping("getAllRoleAjax")
	@ResponseBody
	public List<Role> getAllRoleAjax() {
		return roleService.getAllRole();
	}
	
	@RequestMapping("getPermissionByRoleIdAjax")
	@ResponseBody
	public List<RolePermission> getPermissionByRoleIdAjax(int roleId) {
		return roleService.getPermissionByRoleId(roleId);
	}
	
	@RequestMapping("deleteRoleByRoleIdAjax")
	@ResponseBody
	public int deleteRoleByRoleIdAjax(int roleId) {
		return roleService.deleteRoleByRoleId(roleId);
	}
	
	@RequestMapping("createNewRoleAjax")
	@ResponseBody
	public int createNewRoleAjax(String roleName) {
		role=new Role();
		role.setRoleName(roleName);
		return roleService.createNewRole(role);
	}
	
	@RequestMapping("updateRoleNameAjax")
	@ResponseBody
	public int updateRoleAjax(int roleId,String roleName) {
		role=new Role();
		role.setRoleId(roleId);
		role.setRoleName(roleName);
		return roleService.updateRole(role);
	}
	
	

}
